from models.meta import BaseDocument, IdField, fields


class WebReceivers(BaseDocument):
    meta = {
        'collection': "scan_receivers",
        'primary_key': 'receiver_id',
        'ordering': ['-created_at']
    }

    receiver_id = IdField(required=True, unique=True)
    contact_name = fields.StringField(max_length=50)
    receiver_email = fields.EmailField()
    receiver_type = fields.IntField(choices=[0, 1], default=1)  # 0 default
    user_id = IdField()  # Creator


class WebWarnings(BaseDocument):
    meta = {
        'indexes': ['target_id', 'created_at'],
        'ordering': ['-created_at'],
        'collection': "scan_warnings",
        'primary_key': 'warning_id',
    }

    warning_id = IdField(required=True, unique=True)
    target_group_id = IdField()
    target_id = IdField()
    task_session_id = IdField()
    user_id = IdField()
    task_type = fields.StringField()
    content = fields.StringField()


class WebInboxMails(BaseDocument):
    meta = {
        'indexes': ['created_at', 'user_id'],
        'collection': "scan_inbox_mails",
        'primary_key': 'inbox_mail_id',
        'ordering': ['-created_at'],
    }

    inbox_mail_id = IdField(unique=True, required=True)
    task_session_id = IdField()
    title = fields.StringField()
    content = fields.StringField()
    target_group_id = fields.StringField()
    user_id = fields.StringField()
    status = fields.IntField(default=0, choices=[0, 1])  # 0 unread 1 read
